package com.dcbeida.activity.zyff;


import android.app.Activity;
import android.content.DialogInterface;
import android.support.annotation.Nullable;

import com.dcbeida.bean.CouponDrug;
import com.dcbeida.bean.CpreSendDrug;
import com.dcbeida.bean.DrugCode2Info;
import com.dcbeida.bean.Result_Api;
import com.dcbeida.bean.SendDrugList;
import com.dcbeida.bean.ZyDrugDetail;
import com.dcbeida.callback.DialogCallback;
import com.dcbeida.callback.ErrorCallback;
import com.dcbeida.model.ZyFFModel;

import java.lang.reflect.Type;
import java.util.List;

import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by hp on 2016/5/12.
 */
public class ZyWithGaDetailPresenter implements ZyWithGaDetailContract.Present {


    private ZyWithGaDetailContract.View view;


    private Activity act;

    private ZyFFModel model;

    public ZyWithGaDetailPresenter(ZyWithGaDetailContract.View view, Activity act) {
        //我这里直接把activity作为view，所以不需要
        //mView.setPresenter(this);
        this.view = view;
        this.act = act;
        model = ZyFFModel.newInstance();

    }


    @Override
    public void start() {

    }

    //取消dialog 取消请求
    DialogInterface.OnCancelListener lis = new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            model.getCancel();
        }
    };


    @Override
    public void getorderdrugsv2(String orderId, String parentid) {
        model.getorderdrugsv2(orderId, parentid, new Getorderdrugsv2CallBack(act, ZyDrugDetail.class, lis));
    }

    //根据条形码查询详细信息
    class Getorderdrugsv2CallBack<T> extends DialogCallback<T> {

        public Getorderdrugsv2CallBack(Activity activity, Type type, DialogInterface.OnCancelListener listener) {
            super(activity, type, listener);
        }

        @Override
        public void onResponse(T data) {
            if (data != null) {
                ZyDrugDetail detail = (ZyDrugDetail) data;
                view.showSuccess(detail);
            }

        }

        public void onError(boolean isFromCache, Call call, @Nullable Response response, @Nullable Exception e) {
            super.onError(call, response, e);
            view.showTip("数据未请求成功,请检查网络...");


        }
    }


    class CalcpresenddruglistCallBack<T> extends DialogCallback<T> {

        public CalcpresenddruglistCallBack(Activity activity, Type type, DialogInterface.OnCancelListener listener) {
            super(activity, type, listener);
        }

        @Override
        public void onResponse(T data) {
            if (data != null) {
                SendDrugList sendDrugList = (SendDrugList) data;
                List<CpreSendDrug> list = (List<CpreSendDrug>) sendDrugList.getList();
                //view.showListDrug(list);
            }
        }

        public void onError(boolean isFromCache, Call call, @Nullable Response response, @Nullable Exception e) {
            super.onError(call, response, e);
            view.showTip("数据未请求成功,请检查网络...");


        }
    }


}
